package com.site.wisdom_construction.controller.safetyModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.safetyModule.SafetyDangerRecordLabourService;
import com.site.wisdom_construction.util.verification.NoToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/11
 * @Description
 */
@Api(tags = "劳务人员安全隐患记录接口")
@RestController
@RequestMapping("SafetyDangerRecordLabour")
@CrossOrigin
public class SafetyDangerRecordLabourController {
    @Autowired
    private SafetyDangerRecordLabourService safetyDangerRecordLabourService;

    @ApiOperation(value = "增加劳务人员安全隐患记录信息", notes = "测试数据:")
    @PostMapping("/insertSafetyDangerRecordLabour")
    public JsonResult insertSafetyDangerType(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = safetyDangerRecordLabourService.insertSafetyDangerRecordLabour(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入劳务人员安全隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入劳务人员安全隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除劳务人员安全隐患记录信息", notes = "测试数据:")
    @PostMapping("/deleteSafetyDangerRecordLabour")
    @NoToken
    public JsonResult deleteSafetyDangerRecordLabour(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = safetyDangerRecordLabourService.deleteSafetyDangerRecordLabour(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除劳务人员安全隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除劳务人员安全隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改劳务人员安全隐患记录", notes = "测试数据:")
    @PostMapping("/updateSafetyDangerRecordLabour")
    public JsonResult updateSafetyDangerRecordLabour(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = safetyDangerRecordLabourService.updateSafetyDangerRecordLabour(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改劳务人员安全隐患记录信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改劳务人员安全隐患记录信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询劳务人员安全隐患记录信息", notes = "测试数据:")
    @PostMapping("/findSafetyDangerRecordLabourByPage")
    public Page findSafetyDangerRecordLabourByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(safetyDangerRecordLabourService.Total(map));
        page.setItems(safetyDangerRecordLabourService.findSafetyDangerRecordLabourByPage(map));
        return page;
    }

    @ApiOperation(value = "分页模糊查询劳务人员安全隐患记录信息_劳务人员", notes = "测试数据:")
    @PostMapping("/findSafetyDangerRecordLabourByWorkerId")
    public Page findSafetyDangerRecordLabourByWorkerId(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(safetyDangerRecordLabourService.totalByWorkerId(map));
        page.setItems(safetyDangerRecordLabourService.findSafetyDangerRecordLabourByWorkerId(map));
        return page;
    }

    @ApiOperation(value = "积分TOP榜", notes = "测试数据:")
    @PostMapping("/findSafetyDangerRecordLabourAwarda")
    public OneDataResult findSafetyDangerRecordLabourAwarda(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(safetyDangerRecordLabourService.findSafetyDangerRecordLabourAwarda(map));
        return oneDataResult;
    }
}
